﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
    
<UserControl x:Class="System.Windows.Controls.Samples.ChildWindowSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel Background="White">
        <ContentControl Content="Using a ChildWindow" Style="{StaticResource Header}" />
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel HorizontalAlignment="Center" Width="300" Grid.RowSpan="2">
                <TextBlock Text="Title" Style="{StaticResource ApiName}" Margin="4" />
                <TextBox x:Name="titleText" Text="Child Window Title" Margin="4" />
                <Button Content="Show ChildWindow" Height="23" HorizontalAlignment="Center" Click="Button_Click" Margin="4" />
                <Grid HorizontalAlignment="Stretch" Margin="4">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="DialogResult:" />
                    <TextBlock x:Name="dialogResult" Grid.Column="1" />
                </Grid>
            </StackPanel>
            <ContentControl Content="Select a background image" Grid.Row="0" Grid.Column="1" Margin="4" />
            <ListBox Grid.Row="1" Grid.Column="1"
                  x:Name="thumbs"
                  Style="{StaticResource WrapListBox}"
                  ItemTemplate="{StaticResource PhotographTemplate}"
                  Margin="4" />
        </Grid>
        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="ChildWindowSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;
    
&lt;UserControl x:Class="System.Windows.Controls.Samples.ChildWindowSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    &lt;StackPanel Background="White"&gt;
        &lt;ContentControl Content="Using a ChildWindow" Style="{StaticResource Header}" /&gt;
        &lt;Grid&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition Height="Auto" /&gt;
                &lt;RowDefinition /&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;StackPanel HorizontalAlignment="Center" Width="300" Grid.RowSpan="2"&gt;
                &lt;TextBlock Text="Title" Style="{StaticResource ApiName}" Margin="4" /&gt;
                &lt;TextBox x:Name="titleText" Text="Child Window Title" Margin="4" /&gt;
                &lt;Button Content="Show ChildWindow" Height="23" HorizontalAlignment="Center" Click="Button_Click" Margin="4" /&gt;
                &lt;Grid HorizontalAlignment="Stretch" Margin="4"&gt;
                    &lt;Grid.ColumnDefinitions&gt;
                        &lt;ColumnDefinition /&gt;
                        &lt;ColumnDefinition /&gt;
                    &lt;/Grid.ColumnDefinitions&gt;
                    &lt;TextBlock Text="DialogResult:" /&gt;
                    &lt;TextBlock x:Name="dialogResult" Grid.Column="1" /&gt;
                &lt;/Grid&gt;
            &lt;/StackPanel&gt;
            &lt;ContentControl Content="Select a background image" Grid.Row="0" Grid.Column="1" Margin="4" /&gt;
            &lt;ListBox Grid.Row="1" Grid.Column="1"
                  x:Name="thumbs"
                  Style="{StaticResource WrapListBox}"
                  ItemTemplate="{StaticResource PhotographTemplate}"
                  Margin="4" /&gt;
        &lt;/Grid&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="ChildWindowSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;
using System.Linq;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample page demonstrating the ChildWindow.
    /// &lt;/summary&gt;
    [Sample("ChildWindow", DifficultyLevel.Basic)]
    [Category("ChildWindow")]
    public partial class ChildWindowSample : UserControl
    {
        /// &lt;summary&gt;
        /// Keeps an instance of a ChildWindow that will be shown when a button is clicked.
        /// &lt;/summary&gt;
        private DemoChildWindow dcw;

        /// &lt;summary&gt;
        /// Initializes a new instance of the ChildWindowSample class.
        /// &lt;/summary&gt;
        public ChildWindowSample()
        {
            InitializeComponent();
            dcw = new DemoChildWindow();
            dcw.Closed += new EventHandler(Dcw_Closed);
            thumbs.ItemsSource = from p in Photograph.GetPhotographs()
                                 orderby p.Name
                                 select p;
            thumbs.SelectedIndex = 0;
        }

        /// &lt;summary&gt;
        /// Handles the "Closed" event of the ChildWindow.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;Child Window.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event Arguments.&lt;/param&gt;
        private void Dcw_Closed(object sender, EventArgs e)
        {
            dialogResult.Text = dcw.DialogResult.ToString();
        }

        /// &lt;summary&gt;
        /// Handles clicking the "Show" button.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;Clicked Button.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event Arguments.&lt;/param&gt;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dcw.Title = titleText.Text;
            dcw.DataContext = (from p in Photograph.GetPhotographs()
                               where p.Name.Equals((thumbs.SelectedItem as Photograph).Name)
                               select p).First().Image;
            dcw.Show();
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="ChildWindowSample.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports System.Linq
Imports System.ComponentModel

''' &lt;summary&gt;
''' Sample page demonstrating the ChildWindow.
''' &lt;/summary&gt;
&lt;Sample("ChildWindow", DifficultyLevel.Basic)&gt; _
&lt;Category("ChildWindow")&gt; _
Partial Public Class ChildWindowSample
    Inherits UserControl

    ''' &lt;summary&gt;
    ''' Keeps an instance of a ChildWindow that will be shown when a button is clicked.
    ''' &lt;/summary&gt;
    Private WithEvents dcw As DemoChildWindow

    ''' &lt;summary&gt;
    ''' Initializes a new instance of the ChildWindowSample class.
    ''' &lt;/summary&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification:="InitializeComponent Required by Visual Studio.")&gt; _
    Public Sub New()
        InitializeComponent()
        dcw() = New DemoChildWindow()
        thumbs.ItemsSource = From p In Photograph.GetPhotographs() _
                             Order By p.Name _
                             Select p
        thumbs.SelectedIndex = 0
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the "Closed" event of the ChildWindow.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;Child Window.&lt;/param&gt;
    ''' &lt;param name="e"&gt;Event Arguments.&lt;/param&gt;
    Private Sub Dcw_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles dcw.Closed
        dialogResult.Text = dcw.DialogResult.ToString()
    End Sub

    ''' &lt;summary&gt;
    ''' Handles clicking the "Show" button.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;Clicked Button.&lt;/param&gt;
    ''' &lt;param name="e"&gt;Event Arguments.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        dcw.Title = titleText.Text
        dcw.DataContext = (From p In Photograph.GetPhotographs() _
                           Where p.Name.Equals(DirectCast(thumbs.SelectedItem, Photograph).Name) _
                           Select p).First().Image
        dcw.Show()
    End Sub
End Class</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DemoChildWindow.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;basics:ChildWindow x:Class="System.Windows.Controls.Samples.DemoChildWindow"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
           Width="400" Height="300"
           Title="ChildWindowSample"&gt;
    &lt;Grid Margin="2"&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition /&gt;
            &lt;RowDefinition Height="Auto" /&gt;
            &lt;RowDefinition Height="Auto" /&gt;
        &lt;/Grid.RowDefinitions&gt;

        &lt;ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding}" /&gt;
        &lt;StackPanel Grid.Row="1" x:Name="optionsStack"&gt;
            &lt;Grid HorizontalAlignment="Stretch"&gt;
                &lt;Grid.ColumnDefinitions&gt;
                    &lt;ColumnDefinition Width="Auto" /&gt;
                    &lt;ColumnDefinition /&gt;
                &lt;/Grid.ColumnDefinitions&gt;
                &lt;TextBlock Text="OverlayOpacity: " Margin="4" HorizontalAlignment="Stretch" /&gt;
                &lt;Slider Grid.Column="1" Minimum="0" IsEnabled="True" Maximum="1" Value="{Binding OverlayOpacity, Mode=TwoWay}" HorizontalAlignment="Stretch" /&gt;
            &lt;/Grid&gt;
            &lt;Grid HorizontalAlignment="Stretch"&gt;
                &lt;Grid.ColumnDefinitions&gt;
                    &lt;ColumnDefinition Width="Auto" /&gt;
                    &lt;ColumnDefinition /&gt;
                &lt;/Grid.ColumnDefinitions&gt;
                &lt;TextBlock Text="Overlay Brush: " Margin="4" /&gt;
                &lt;ComboBox SelectedItem="{Binding OverlayBrush, Mode=TwoWay}" Grid.Column="1" IsEnabled="True" HorizontalAlignment="Stretch"&gt;
                    &lt;ComboBox.ItemTemplate&gt;
                        &lt;DataTemplate&gt;
                            &lt;StackPanel Orientation="Horizontal"&gt;
                                &lt;TextBlock Margin="2" Text="{Binding Color}" FontFamily="Consolas" VerticalAlignment="Center" /&gt;
                                &lt;Rectangle Fill="{Binding}" Margin="2" Stroke="Black" Height="14" Width="75" /&gt;
                            &lt;/StackPanel&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/ComboBox.ItemTemplate&gt;
                    &lt;SolidColorBrush Color="White" Opacity=".7"  /&gt;
                    &lt;SolidColorBrush Color="Black" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Blue" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Yellow" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Pink" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Orange" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Green" Opacity=".7" /&gt;
                    &lt;SolidColorBrush Color="Red" Opacity=".7" /&gt;
                &lt;/ComboBox&gt;
            &lt;/Grid&gt;
        &lt;/StackPanel&gt;
        &lt;Button Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="2" /&gt;
        &lt;Button Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right"  Margin="0,12,79,0" Grid.Row="2" /&gt;
    &lt;/Grid&gt;
&lt;/basics:ChildWindow&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DemoChildWindow.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample ChildWindow for demonstration purposes.
    /// &lt;/summary&gt;
    public partial class DemoChildWindow : ChildWindow
    {
        /// &lt;summary&gt;
        /// Initializes a DemoChildWindow.
        /// &lt;/summary&gt;
        public DemoChildWindow()
        {
            InitializeComponent();
            optionsStack.DataContext = this;
        }

        /// &lt;summary&gt;
        /// Handles the Click event of the OK button.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;OK Button.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        /// &lt;summary&gt;
        /// Handles the Click event of the Cancel button.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;Cancel button.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DemoChildWindow.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

''' &lt;summary&gt;
''' Sample ChildWindow for demonstration purposes.
''' &lt;/summary&gt;
Partial Public Class DemoChildWindow
    Inherits ChildWindow

    ''' &lt;summary&gt;
    ''' Initializes a DemoChildWindow.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
        optionsStack.DataContext = Me
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the Click event of the OK button.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;OK Button.&lt;/param&gt;
    ''' &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub OKButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        DialogResult = True
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the Click event of the Cancel button.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;Cancel button.&lt;/param&gt;
    ''' &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub CancelButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        DialogResult = False
    End Sub
End Class</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>
</UserControl>
